/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lucene.Analyzers;

import java.io.Reader;
import java.util.Iterator;
import java.util.Set;
import lucene.Analyzers.stantard.StandardAnalyzer;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.PorterStemFilter;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.StopFilter;
import org.apache.lucene.analysis.TokenStream;
//import org.apache.lucene.analysis.standard.StandardAnalyzer;

public class StemmingPositionStopTwitterAnalyzer extends Analyzer {
    private Set stopWords;
    
    public StemmingPositionStopTwitterAnalyzer() {
        this(StopAnalyzer.ENGLISH_STOP_WORDS);        
    }
    
    public StemmingPositionStopTwitterAnalyzer(String[] stopList) {
        stopWords = StopFilter.makeStopSet(stopList);
        stopWords.add("i");
        stopWords.add("about");
        stopWords.add("also");
        stopWords.add("any");
        stopWords.add("aren");
        stopWords.add("arent");
        stopWords.add("around");
        stopWords.add("because");
        stopWords.add("been");        
        stopWords.add("before");
        stopWords.add("being");
        stopWords.add("between");
        stopWords.add("both");
        stopWords.add("can");
        stopWords.add("cannot");
        stopWords.add("cant");
        stopWords.add("come");
        stopWords.add("could");
        stopWords.add("day");
        stopWords.add("did");
        stopWords.add("didn");
        stopWords.add("didnt");
        stopWords.add("do");
        stopWords.add("doe");
        stopWords.add("does");
        stopWords.add("doesn");
        stopWords.add("doesnt");
        stopWords.add("dont");
        stopWords.add("don");
        stopWords.add("either");
        stopWords.add("even");
        stopWords.add("every");
        stopWords.add("from");
        stopWords.add("get");
        stopWords.add("great");
        stopWords.add("had");
        stopWords.add("has");
        stopWords.add("hasn");
        stopWords.add("hasnt");
        stopWords.add("have");
        stopWords.add("haven");
        stopWords.add("havent");
        stopWords.add("havn");
        stopWords.add("havnt");
        stopWords.add("he");
        //stopWords.add("help");
        stopWords.add("her");
        stopWords.add("here");
        stopWords.add("him");
        stopWords.add("his");
        stopWords.add("how");
        //stopWords.add("info");
        stopWords.add("is");
        stopWords.add("its");
        stopWords.add("just");
        stopWords.add("let");
        //stopWords.add("life");
        //stopWords.add("live");
        stopWords.add("many");
        stopWords.add("may");
        stopWords.add("me");
        stopWords.add("most");
        stopWords.add("more");
        stopWords.add("much");
        stopWords.add("must");
        stopWords.add("mustn");
        stopWords.add("mustnt");
        stopWords.add("my");
        stopWords.add("need");
        stopWords.add("one");
        stopWords.add("only");
        stopWords.add("other");
        stopWords.add("our");
        stopWords.add("please");
        //stopWords.add("question");
        stopWords.add("re");
        stopWords.add("really");
        stopWords.add("regard");
        stopWords.add("said");
        stopWords.add("say");
        stopWords.add("see");
        stopWords.add("she");
        stopWords.add("should");
        stopWords.add("since");
        stopWords.add("so");
        stopWords.add("some");
        stopWords.add("still");
        //stopWords.add("story");
        stopWords.add("take");
        stopWords.add("than");
        stopWords.add("thank");
        stopWords.add("thanks");
        stopWords.add("them");
        stopWords.add("thing");
        stopWords.add("those");
        //stopWords.add("thought");
        //stopWords.add("think");
        stopWords.add("through");
        stopWords.add("thru");
        stopWords.add("thus");
        stopWords.add("told");
        stopWords.add("tell");
        stopWords.add("too");
        stopWords.add("use");
        stopWords.add("used");
        stopWords.add("uses");
        stopWords.add("using");
        stopWords.add("ve");
        stopWords.add("very");
        stopWords.add("want");
        //stopWords.add("way");
        stopWords.add("we");
        stopWords.add("well");
        stopWords.add("were");
        stopWords.add("what");
        stopWords.add("when");
        stopWords.add("where");
        stopWords.add("which");
        stopWords.add("who");
        stopWords.add("why");
        stopWords.add("whithout");
        stopWords.add("won");
        stopWords.add("wont");
        stopWords.add("would");
        stopWords.add("you");
        stopWords.add("your");
        stopWords.add("you'r");
        stopWords.add("you'll");
        stopWords.add("youll");
        stopWords.add("i'll");
        //stopWords.add("ill");
        stopWords.add("we'll");
        //stopWords.add("well");
        stopWords.add("she'll");
        //stopWords.add("shell");
        stopWords.add("he'll");
        //stopWords.add("hell");
        stopWords.add("they'll");
        stopWords.add("theyll");
        stopWords.add("im");
        stopWords.add("i'm");

        /*Iterator sw = stopWords.iterator();
        System.out.print("\n\n STOP WORDS");
        while(sw.hasNext()){
            System.out.print("\"" + sw.next() + "\", ");
        }*/
    }
    
    public TokenStream tokenStream(String fieldName, Reader reader) {
        
        return new PorterStemFilter( 
                new PositionStopFilter(
                        new PositionTwitterFilter(
                                new StandardAnalyzer().tokenStream(fieldName, reader)),stopWords));
    }

}
